/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.ayd2_fase2;

import com.mysql.jdbc.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 *
 * @author dev
 */
public class conexion {
    
    Connection conn = null;
    String dbadmin;
    String dbnombre;
    String dbpassadmin;
    String driver = "com.mysql.jdbc.Driver";
    String url = "jdbc:mysql://localhost:3306/";
    
    
    
    public conexion(String usr, String pass, String db){
        dbadmin = usr;
        dbpassadmin = pass;
        dbnombre = db;
        
        try {
            Class.forName(driver); 
            conn = (Connection) DriverManager.getConnection(url + dbnombre, dbadmin, dbpassadmin);
        } catch (ClassNotFoundException ex) {
            System.out.println("Error, clase no encontrada" + ex.getMessage());
        } catch(SQLException ex){
            System.out.println("Error en la instruccion SQL" + ex.getMessage());
        }
    }
    
    public Connection getConexion(){
        return conn;
    }
    
    public void closeConexion(){
        if(conn != null){
            try {
                conn.close();
            } catch (SQLException ex) {
                System.out.println("Error en la instruccion SQL" + ex.getMessage());
            }
        }
    }
}
